package J4_25;

public class test {
    public int getLongestPalindrome (String s) {
        // write code here
        int n = s.length();
        boolean[][] dp = new boolean[n][n];
        int begin = 0, len = 1; // 标记⼀下最⻓⼦串的起始位置和⻓度
        for(int i = n - 1; i >= 0; i--)
        {
            for(int j = i; j < n; j++)
            {
                if(s.charAt(i) == s.charAt(j))
                    dp[i][j] = i + 1 < j ? dp[i + 1][j - 1] : true;
                if(dp[i][j] && j - i + 1 > len)
                {
                    len = j - i + 1;
                    begin = i;
                }
            }
        }
        return len;
    }
}
